﻿using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core.ServiceModel;
using Telerik.Windows.Controls;

namespace Baosight.ZNH.ZM.UI
{
    // <summary>
    /// 选择模块
    /// </summary>
    /// Title:SelectModule
    /// Copyright:Baosight Software LTD.co Copyright (c) 2011
    /// Company:上海宝信软件股份有限公司
    /// Author: 高强
    /// Version: 1.0
    /// History:
    ///       2012-12-07  高强   [创建]
    ///  
    public partial class SelectModule : EFViewCmes
    {
        private Button but;

        public SelectModule()
        {
            InitializeComponent();
        }


        public static void AddEIColumnsToEIBlock(EIBlock block, string[] columns)
        {
            EIColumn c;
            foreach (var item in columns)
            {
                c = new EIColumn();
                c.SetName(item);
                block.AddColumn(c);
            }
        }

        /// <summary>
        /// 确定按钮按下增加隐患项目
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btnSelectConfirm(object sender, RoutedEventArgs e)
        {
            List<EIRow> rowTemp = grid.GetCheckedEIRows();
            but = sender as Button;
            but.IsEnabled = false;
            if (rowTemp.Count != 0)
            {
                EIInfo eiInfo = this.BuildEIData(OperationMode.Query, this.eServiceName, "insert", DataRange.CheckedItems, null);
                eiInfo.Set("fdDepartmentId", this.fdDepartmentId.Value.ToString());
                HttpServiceAgent agent = new HttpServiceAgent();
                agent.CallService(eiInfo, DoWorkCompleted, DoWorkError);
            }
            else
            {
                DialogParameters param = new DialogParameters();
                param.CancelButtonContent = "取消";
                param.OkButtonContent = "确定";
                param.Content = "请选择模块";
                param.Header = "提示框";
                EFWindow.Alert(param);
                but.IsEnabled = true;
            }

        }

        /// <summary>
        /// 返回错误处理信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DoWorkError(object sender, DoWorkErroredEventArgs e)
        {
            EFWindow.Alert(e.Exception.Message);
        }

        /// <summary>
        /// 回调
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DoWorkCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            EIInfo inInfo = e.EIInfo;
            if (inInfo.Status == -1)
            {
                string _msg;
                if (inInfo.GetMsg() == null || inInfo.GetMsg() == "")
                {
                    _msg = "新增模块操作失败！";
                }
                else
                {
                    _msg = inInfo.GetMsg();
                }
                string str = "操作：" + _msg;
                DialogParameters param = new DialogParameters();
                param.CancelButtonContent = "取消";
                param.OkButtonContent = "确定";
                param.Content = str;
                param.Header = "提示框";
                EFWindow.Alert(param);
                but.IsEnabled = true;
            }
            else
            {
                EFWindow wnd = Parent as EFWindow;
                wnd.Close();
                wnd.DialogResult = true;

            }
        }

        /// <summary>
        /// 返回按钮按下
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btnSelectCancle(object sender, RoutedEventArgs e)
        {
            EFWindow wnd = Parent as EFWindow;
            wnd.DialogResult = false;
            wnd.Close();
        }
    }
}
